-- David Siegel, Jonathan Coveney, HW #8

module TermLexer (Token (..), lexT,
                  test
                 ) where

import Char
import Parsing hiding (test)

------------------------------------------------------------
-- Public method declarations
------------------------------------------------------------

lexT :: String -> [Token]

test :: IO ()

------------------------------------------------------------
-- Private types
------------------------------------------------------------

data Token =  TChar Char
            | TAnd
            | TOr
            | TNot
            | TEq
            | TLess
            | TGreater
            | TOpen
            | TClose
            | TTrue
            | TFalse
  deriving (Eq, Show)

------------------------------------------------------------
-- Private method declarations
------------------------------------------------------------

-- Parse a string to tokens.
tokenize :: Parser Char [Token]

-- Token eats a space, number, operator, parentheses, and fails
-- otherwise.
token :: Parser Char [Token]

------------------------------------------------------------
-- Public method definitions
------------------------------------------------------------

lexT = fst. head . (applyParser tokenize)

------------------------------------------------------------
-- Private method definitions
------------------------------------------------------------

tokenize = do x <- token
              xs <- tokenize
              return (x ++ xs)
           `chooseP`
           token

token = do y <- alphachar
           if y == 'T'
             then return [TTrue]
             else if y == 'F'
                    then return [TFalse]
                    else return [TChar y]
        `chooseP`
        do x <- item
           case x of
             '&' -> return [TAnd]
             '|' -> return [TOr]
             '~' -> return [TNot]
             '=' -> return [TEq]
             '<' -> return [TLess]
             '>' -> return [TGreater]
             '(' -> return [TOpen]
             ')' -> return [TClose]
             _   -> return []

------------------------------------------------------------
-- Testing
------------------------------------------------------------

test = return ()



